package com.xbongbong.crm.help;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasMenuEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author mingliang.cao
 * @date 2022/10/11 14:47
 */
@Component
public class CustomerHelp {

    @Resource
    private PaasMenuModel paasMenuModel;
    /**
     * 根据公司id获得合同，机会报价单的名字菜单的最新名字
     * 感觉在菜单设置保存后数据入缓存好一些
     * @param corpid
     * @return
     */
    public Map<String, String> getMenuMap(String corpid) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(StringConstant.CORPID, corpid);
        param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
        param.put(StringConstant.DISTRIBUTOR_MARK, DistributorMarkEnum.OTHER.getCode());
        param.put("aliasIn", Arrays.asList(XbbRefTypeEnum.CONTRACT.getAlias(), XbbRefTypeEnum.SALES_OPPORTUNITY.getAlias(), XbbRefTypeEnum.QUOTATION.getAlias()));
        List<PaasMenuEntity> menuEntityList = paasMenuModel.findEntitys(param);
        if (CollectionsUtil.isEmpty(menuEntityList)) {
            return new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        } else {
            return menuEntityList.stream().collect(Collectors.toMap(PaasMenuEntity::getAlias, PaasMenuEntity::getName, (key1, key2) -> key2));
        }
    }
}
